<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'mortgage.label', default: 'Mortgage')}"/>
    <title>贷款</title>
    <style>
    .table>tbody>tr>td{
        vertical-align: middle;
    }
    @media screen and (min-width:1900px) and (max-width:1920px) {
        .flex{
            display: flex;justify-content: center;align-items: center;
        }
    }
    .select2-container .select2-choices .select2-search-field input,.select2-container .select2-choice,.select2-container .select2-choices{

        color: #999;
    }
    </style>
</head>

<body class="fixed-navbar fixed-sidebar">

<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right">
                <ol class="hbreadcrumb breadcrumb">
                    <li>CINDATA PLS</li>
                    <li class="active">
                        <span>命中反欺诈</span>
                    </li>
                </ol>
            </div>
            <h2 class="font-light m-b-xs">
                命中反欺诈
            </h2>
        </div>
    </div>
</div>

<div class="content animate-panel">
    <div class="row">
        <g:form method="POST" action="antiFraudWarning" class="form-horizontal" role="form" id="form">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    <div class="panel-tools">
                        <button class="btn btn-primary btn-xs" type="submit" id="searchBtn"><i class="fa fa-search"></i> 查询</button>
                        <button class="btn btn-warning2 btn-xs" type="button" id="resetBtn">
                            <i class="fa fa-times"></i> 重置</button>
                    </div>
                    查询
                </div>
                <div class="panel-body seach-group" id="bug1">

                <div class="row">
                    <div class="form-group col-sm-4">
                        <label for="district" class="col-sm-3 control-label">城市</label>
                        <div class="col-sm-9">
                            <g:select class="form-control" name="city" id="city" from="${com.cindata.City.findAllByNameInList(new com.cindata.ComponentService().evaluate(com.cindata.Component.findByCode('showCity')), [sort: 'name', order: 'asc'])}"
                                valueMessagePrefix="status" optionKey="zoneNumber" optionValue="name" value="${params?.city}" noSelection="${['-1': '请选择城市']}"/>
                            <input type="hidden" id="communityId" value="${params?.communityId}" name="communityId" />
                        </div>
                    </div>
                    <div class="form-group col-sm-4">
                        <label for="district" class="col-sm-3 control-label">行政区</label>
                        <div class="col-sm-9">
                            <g:select class="form-control" name="district" id="district" from="${districtList}" valueMessagePrefix="status" optionKey="zoneNumber" optionValue="name" value="${params?.district}" noSelection="${['null': '请选择行政区']}"/>
                        </div>
                    </div>
                    <div class="form-group col-sm-4">
                        <label for="district" class="col-sm-3 control-label">借款人姓名</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control " placeholder="请输入借款人姓名" id="borrName" value="${params?.borrName}" name="borrName" />
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="form-group col-sm-4">
                        <label for="district" class="col-sm-3 control-label">贷款编号</label>
                        <div class="col-sm-9 input-group" style="display: flex;justify-content: center">
                            <input type="text" class="form-control " placeholder="请输入贷款编号" id="serialNumber" value="${params?.serialNumber}" name="serialNumber" />
                        </div>
                    </div>
                    <div class="form-group col-sm-4">
                        <label for="district" class="col-sm-3 control-label">证件类型</label>
                        <div class="col-sm-9 input-group" style="display: flex;justify-content: center">
                            <g:select class="form-control" name="borridCardType" id="borridCardType" from="${['身份证']}" value="身份证" noSelection="${['': '请选择证件类型']}"/>
                        </div>
                    </div>
                    <div class="form-group col-sm-4">
                        <label for="district" class="col-sm-3 control-label">证件号</label>
                        <div class="col-sm-9 input-group" style="display: flex;justify-content: center">
                            <input type="text" class="form-control " placeholder="请输入证件号码" id="borrIdCardNo" value="${params?.borrIdCardNo}" name="borrIdCardNo" />
                        </div>
                    </div>
                </div>

            </div>
        </g:form>
    </div>
    <div class="row">
        <div class="hpanel hgreen">
            <div class="panel-heading">
                <div class="panel-tools">
                    <a class="btn btn-primary btn-xs" type="submit" href="/riskWarning/releaseAntiFraudWarning"><i class="fa fa-paper-plane"></i> 发布预警</a>
                    <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                </div>
                全部命中反欺诈
            </div>

            <div class="panel-body no-padding">
                <div class="table-responsive">
                    <table cellpadding="1" cellspacing="1" class="table table-striped table-bordered table-hover text-center"  id="esateTable">
                        <thead>
                        <tr>
                            <g:sortableColumn property="serialNumber" title="贷款编号" class="" params="${params}"/>
                            <g:sortableColumn property="externalId" title="押品编号" class="" params="${params}"/>
                            <g:sortableColumn property="borrName" title="借款人姓名"  class="" params="${params}"/>
                            <g:sortableColumn property="borridCardType" title="证件类型"  class="" params="${params}"/>
                            <g:sortableColumn property="borrIdCardNo" title="证件号码"  class="" params="${params}"/>
                            <g:sortableColumn property="city" title="城市"  class="" params="${params}"/>
                            <g:sortableColumn property="district" title="行政区"  class="" params="${params}"/>
                            <g:sortableColumn property="loansAmount" title="贷款金额(元)"  class="" params="${params}"/>
                            <g:sortableColumn property="loansBalance" title="贷款余额(元)"  class=" " params="${params}"/>
                            <g:sortableColumn property="totalPrice" title="信用额度(元)"  class="" params="${params}"/>
                            <g:sortableColumn property="totalBalance" title="信用余额"  class=" " params="${params}"/>
                            <g:sortableColumn property="isAntiFraud" title="反欺诈"  class=" " params="${params}"/>
                            <g:sortableColumn property="dealType" title="处置类型"  class="" params="${params}"/>
                            <th class="col-md-1 text-center sortable" colspan="2" style="color: #34495e;">操作项</th>
                        </tr>
                        </thead>
                        <tbody>
                        <g:each in="${mortgageList}">
                            <tr>
                                <td class="text-center"><g:link style="color: #3498DB" controller="mortgage" action="show" id="${it?.id}" class="firstTd">${it?.serialNumber}</g:link></td>
                                <td class="text-center">${it?.externalId}</td>
                                <td class="text-center">${it?.borrName ? it?.borrName : '-'}</td>
                                <td class="text-center">身份证</td>
                                <td class="text-center">${it?.borrIdCardNo ? it?.borrIdCardNo : '-'}</td>
                                <td class="text-center">${it?.account?.city?.name ? it?.account?.city?.name : '-'}</td>
                                <td class="text-center">${it?.account?.district?.name ? it?.account?.district?.name : '-'}</td>
                                <td class="text-center">${it?.loansAmount ? it?.loansAmount : '-'}</td>
                                <td class="text-center">${it?.loansBalance ? it?.loansBalance : ''}</td>
                                <td class="text-center">${it?.totalPrice ? it?.totalPrice : '-'}</td>
                                <td class="text-center">${it?.totalPrice && it?.loansBalance ? it?.totalPrice - it?.loansBalance : '-'}</td>
                                <td class="text-center">${it?.isAntiFraud ? '命中' : '未命中'}</td>
                                <td class="text-center">${it?.dealType?.name}</td>
                                <g:if test="${it?.warningStatus?.name == '已处置'}">
                                    <td class="text-center">
                                        <div style="margin-bottom: 2px;">
                                            <div class="btn btn-xs btn-outline btn-success" style="color: #fff" disabled>
                                                已处置
                                            </div>
                                        </div>
                                    </td>
                                    <td class="text-center">
                                        <div class="btn btn-xs btn-outline btn-danger" style="width: 52px; margin-top: 2px;color: #fff" disabled>
                                            删除
                                        </div>
                                    </td>
                                </g:if>
                                <g:else>
                                    <td class="text-center">
                                        <div style="margin-bottom: 2px;">
                                            <a href="${it?.id}" class="btn btn-xs btn-outline btn-success handleButton">
                                                已处置
                                            </a>
                                        </div>
                                    </td>
                                    <td class="text-center">
                                        <a href="${it?.id}" class="btn btn-xs btn-outline btn-danger deleteButton" style="width: 52px; margin-top: 2px;">
                                            删除
                                        </a>
                                    </td>
                                </g:else>
                            </tr>
                        </g:each>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="panel-footer">
                <div class="pagination">
                    <g:paginate action="antiFraudWarning" total="${mortgageCount ?: 0}" params="${params}"/>
                </div>
            </div>
        </div>
    </div>
</div>

</div>

<g:javascript>
    $(".handleButton").click(function(event){
        event.preventDefault();
        var id = $(this).attr("href");
        swal({
                title: "该笔贷款已经完成预警处置吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true
            },
            function(){
                $.ajax({
                    url:'/riskWarning/disposalAntiFraud',
                    data:{
                        id:id
                    },
                    type:"post",
                    success:function(data)
                    {
                        if(data.status=="success"){
                            $("#searchBtn").click();
                        }else{
                            swal("已处置失败，请稍后重试", "", "error");
                        }
                    }
                })

            });
    });
    $(".deleteButton").click(function(event){
        event.preventDefault();
        var id = $(this).attr("href");
        swal({
                title: "确定删除该笔贷款的预警处置吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true
            },
            function(){
                $.ajax({
                    url:'/riskWarning/deleteAntiFraud',
                    data:{
                        id:id
                    },
                    type:"post",
                    success:function(data)
                    {
                        if(data.status=="success"){
                            $("#searchBtn").click();
                        }else{
                            swal("删除失败，请稍后重试", "", "error");
                        }
                    }
                })
            })
    });

    //城市切换
    $("#city").bind("change", function(){
        $("#district option").remove();
        $("#s2id_district span:first").html("请选择行政区");
        var city = $("#city").val();
        $("#district").append("<option value='-1' >请选择行政区</option>");
        if(city=='-1'){
            return
        }
        $.ajax({
            url: "/estate/districtList",
            type: "POST",
            data: {'city': city} ,
            success: function(result){
                for(var i=0; i < result.districtList.length; i++){
                    $("#district").append("<option value=" + result.districtList[i].zoneNumber + ">" + result.districtList[i].name + "</option>")
                }
            }
        });
    });

    //重置按钮
    $("#resetBtn").click(function () {
        $("#communityId").val("");
        $("#s2id_city span:first").html("请选择城市");
        $("#city").val("");
        $("#s2id_district span:first").html("请选择行政区");
        $("#district").val("");
        $("#serialNumber").val("");
        $("#borrName").val("");
        $("#borrIdCardNo").val("");
        $("#s2id_borridCardType span:first").html("身份证");
    });
</g:javascript>

</body>
</html>
